/* 
 * Advanced Foundation Classes
 * Copyright (C) 2000/2004  Fabio Rotondo - Andrea Galimberti
 *  
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *  
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *  
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 */
#include "label.h"

static const char class_name [] = "EGUI Widget Label";

static int afc_easygui_internal_label_get_template ( DynamicClass * dyn );
static int afc_easygui_internal_cb_label ( DynamicClass * dyn );
static int afc_easygui_label_method_set_text ( DynamicClass * dyn );

DynamicClass * afc_easygui_internal_label_new_instance ()
{
	DynamicClass * dyn = NULL;

	if ( ( dyn = afc_dynamic_class_new () ) == NULL ) {
		AFC_LOG_FAST_INFO ( AFC_ERR_NO_MEMORY, "dynamic class: label" );
		return ( NULL );
	}

	afc_dynamic_class_add_method ( dyn, "get_template", NULL,  afc_easygui_internal_label_get_template );
	afc_dynamic_class_add_method ( dyn, "open_callback", NULL,  afc_easygui_internal_cb_label );
	afc_dynamic_class_add_method ( dyn, "enabled",	NULL, 	afc_easygui_widget_method_enabled );

	afc_dynamic_class_add_method ( dyn, "set_text", NULL,       afc_easygui_label_method_set_text );

	return ( dyn );
}

int afc_easygui_internal_label_del_instance ( DynamicClass * dyn )
{
	return ( afc_easygui_widget_standard_free ( dyn ) );
	/*
	if ( dyn != NULL ) afc_dynamic_class_delete ( dyn );

	return ( AFC_ERR_NO_ERROR );
	*/
}

static int afc_easygui_internal_label_get_template ( DynamicClass * dyn )
{
	dyn->result = "TEXT WRAP/S";
	return ( AFC_ERR_NO_ERROR );
}

static int afc_easygui_internal_cb_label ( DynamicClass * dyn )
{
	EasyGUI * egui = dyn->info;
	EasyGUIContext * context = egui->curr_context;
	GtkWidget * w;
	char * label = NULL;
	short  wrap;
	DynamicClass * dc;

	if ( context->curr_container == NULL ) return ( AFC_EASYGUI_ERR_NO_CONTAINER );

	afc_easygui_widget_parse_default_params ( context->egui );

	label = afc_cmd_parser_arg_get_by_name ( context->egui->parser, "TEXT" );
	wrap  = ( short ) ( int ) afc_cmd_parser_arg_get_by_name ( context->egui->parser, "WRAP" );

	if ( ( dc = afc_dynamic_class_master_new_instance ( context->egui->commands, "label" ) ) == NULL )
		return ( AFC_LOG_FAST_INFO ( AFC_ERR_NO_MEMORY, "dynclass instance" ) );

	WIDGET_SET_CONTEXT ( dc, context );

	w = gtk_label_new ( "-" );

	if ( wrap ) gtk_label_set_line_wrap ( GTK_LABEL ( w ), TRUE );

	if ( label ) gtk_label_set_markup ( GTK_LABEL ( w ), label );

	return ( afc_easygui_internal_add_widget ( context, w, dc ) );
}

// METHODS
static int afc_easygui_label_method_set_text ( DynamicClass * dyn )
{
	char * text;
	EasyGUIWidgetData * ewidget;

	WIDGET_GET_EWIDGET(dyn,ewidget);

	text = afc_array_master_first ( dyn->args );

	// gtk_label_set_text ( GTK_LABEL ( ewidget->gtk_handle ), text );
	gtk_label_set_markup ( GTK_LABEL ( ewidget->gtk_handle ), text );

	return ( AFC_ERR_NO_ERROR );
	
}
